package com.ourteam.product.requirement.dao.impl;

import com.ourteam.product.requirement.dao.IProductGlossaryAttrDAO;
import com.ourteam.product.requirement.dao.ProductGlossaryAttr;
import com.ourteam.product.requirement.dao.ProductGlossaryAttrDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2018-05-03 16:45:42
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractProductGlossaryAttrDAOJdbcImpl extends AbstractSpringDAO
    implements IProductGlossaryAttrDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, ProductDefineId, ProductGlossaryId, AttrName, AttrType, DataRule,
            Status, Remarks, IsRequire
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.ProductDefineId,
            _DataObjectProperty.ProductGlossaryId, _DataObjectProperty.AttrName,
            _DataObjectProperty.AttrType, _DataObjectProperty.DataRule,
            _DataObjectProperty.Status, _DataObjectProperty.Remarks,
            _DataObjectProperty.IsRequire
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<ProductGlossaryAttr, ProductGlossaryAttrDAOQueryBean> daoHelper;

    public AbstractProductGlossaryAttrDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<ProductGlossaryAttr, ProductGlossaryAttrDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aProductGlossaryAttr
         * @throws Exception
         */
    public boolean checkIsUnique(ProductGlossaryAttr aProductGlossaryAttr)
        throws Exception {
        if (aProductGlossaryAttr == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aProductGlossaryAttr.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aProductGlossaryAttr
     * @throws Exception
     */
    public void insert(ProductGlossaryAttr aProductGlossaryAttr)
        throws Exception {
        super.doInsert(aProductGlossaryAttr);
    }

    /**
         * Batch Insert Datas
         * @param aProductGlossaryAttr
         * @throws Exception
         */
    public void batchInsert(ProductGlossaryAttr[] aProductGlossaryAttrs)
        throws Exception {
        super.doBatchInsert(aProductGlossaryAttrs);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(ProductGlossaryAttrDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(ProductGlossaryAttr aProductGlossaryAttr)
        throws Exception {
        delete(aProductGlossaryAttr.getId());
    }

    /**
     * Update Data Selective
     * @param aProductGlossaryAttr
     * @throws Exception
     */
    public void update(ProductGlossaryAttr aProductGlossaryAttr)
        throws Exception {
        if (aProductGlossaryAttr.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aProductGlossaryAttr);

        ProductGlossaryAttr tempObj = findById(aProductGlossaryAttr.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aProductGlossaryAttr, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aProductGlossaryAttrs[]
     * @throws Exception
     */
    public void batchUpdate(ProductGlossaryAttr[] aProductGlossaryAttrs)
        throws Exception {
        super.doBatchUpdate(aProductGlossaryAttrs);
    }

    /**
         * Update Data By Condictions
         * @param aProductGlossaryAttr
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(ProductGlossaryAttr aProductGlossaryAttr,
        ProductGlossaryAttrDAOQueryBean aQueryBean) throws Exception {
        super.doUpdateByQuery(aProductGlossaryAttr, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(ProductGlossaryAttrDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(ProductGlossaryAttr aProductGlossaryAttr)
        throws Exception {
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public ProductGlossaryAttr findById(final long id)
        throws Exception {
        ProductGlossaryAttrDAOQueryBean queryBean = new ProductGlossaryAttrDAOQueryBean();

        ProductGlossaryAttrDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        ProductGlossaryAttr[] ProductGlossaryAttrs = query(queryBean);

        if (ProductGlossaryAttrs.length == 0) {
            return null;
        } else {
            return ProductGlossaryAttrs[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return ProductGlossaryAttr[]
         * @throws Exception
         */
    public ProductGlossaryAttr[] query(
        ProductGlossaryAttrDAOQueryBean queryBean) throws Exception {
        List result = super.doQuery(queryBean,
                new JdbcProductGlossaryAttrRowMapper());

        return (ProductGlossaryAttr[]) result.toArray(new ProductGlossaryAttr[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        ProductGlossaryAttrDAOQueryBean queryBean) throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(ProductGlossaryAttrDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(ProductGlossaryAttr[] aProductGlossaryAttrs,
        ProductGlossaryAttrDAOQueryBean queryBean) throws Exception {
        daoHelper.synchronize(aProductGlossaryAttrs, queryBean);
    }

    public void synchronize(ProductGlossaryAttr[] aProductGlossaryAttrs,
        ProductGlossaryAttrDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<ProductGlossaryAttr> callBack)
        throws Exception {
        daoHelper.synchronize(aProductGlossaryAttrs, queryBean, callBack);
    }

    public static class JdbcProductGlossaryAttrRowMapper implements RowMapper<ProductGlossaryAttr> {
        public ProductGlossaryAttr mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            ProductGlossaryAttr object = new ProductGlossaryAttr();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object productDefineId = null;

                productDefineId = resultSet.getObject(columnIndex++);

                object.setProductDefineIdNull(resultSet.getBoolean(
                        columnIndex++));

                if (productDefineId != null) {
                    setBeanValue(object, _DataObjectProperty.ProductDefineId,
                        productDefineId);
                }

                Object productGlossaryId = null;

                productGlossaryId = resultSet.getObject(columnIndex++);

                object.setProductGlossaryIdNull(resultSet.getBoolean(
                        columnIndex++));

                if (productGlossaryId != null) {
                    setBeanValue(object, _DataObjectProperty.ProductGlossaryId,
                        productGlossaryId);
                }

                Object attrName = null;

                attrName = resultSet.getObject(columnIndex++);

                object.setAttrNameNull(resultSet.getBoolean(columnIndex++));

                if (attrName != null) {
                    setBeanValue(object, _DataObjectProperty.AttrName, attrName);
                }

                Object attrType = null;

                attrType = resultSet.getObject(columnIndex++);

                object.setAttrTypeNull(resultSet.getBoolean(columnIndex++));

                if (attrType != null) {
                    setBeanValue(object, _DataObjectProperty.AttrType, attrType);
                }

                Object dataRule = null;

                dataRule = resultSet.getObject(columnIndex++);

                object.setDataRuleNull(resultSet.getBoolean(columnIndex++));

                if (dataRule != null) {
                    setBeanValue(object, _DataObjectProperty.DataRule, dataRule);
                }

                Object status = null;

                status = resultSet.getObject(columnIndex++);

                object.setStatusNull(resultSet.getBoolean(columnIndex++));

                if (status != null) {
                    setBeanValue(object, _DataObjectProperty.Status, status);
                }

                Object remarks = null;

                remarks = resultSet.getObject(columnIndex++);

                object.setRemarksNull(resultSet.getBoolean(columnIndex++));

                if (remarks != null) {
                    setBeanValue(object, _DataObjectProperty.Remarks, remarks);
                }

                Object isRequire = null;

                isRequire = resultSet.getObject(columnIndex++);

                object.setIsRequireNull(resultSet.getBoolean(columnIndex++));

                if (isRequire != null) {
                    setBeanValue(object, _DataObjectProperty.IsRequire,
                        isRequire);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
